export const throttle = (method, delay, duration) => {
  let timer = null;
  let begin = new Date();
  return function () {
    const context = this; const args = arguments; const current = new Date();
    clearTimeout(timer);
    if (current - begin >= duration) {
      method.apply(context, args);
      begin = current;
    } else {
      timer = setTimeout(() => {
        method.apply(context, args);
      }, delay);
    }
  };
};

export const debounce = (fn, wait) => {
  let timeout = null;
  wait = wait || 600;
  return function () {
    const that = this;
    if (timeout !== null) clearTimeout(timeout);
    timeout = setTimeout(() => {
      fn.apply(that);
    }, wait);
  };
};

export default val => val.replace(/(.{6})(.+)(.{4})/, '$1...$3');
